<!DOCTYPE html>
<html>
<head>
    <meta name="layout" content="main"/>
    <g:set var="entityName" value="${message(code: 'account.label', default: 'Account')}"/>
    <title>新增机构</title>
</head>

<body>
<div class="small-header">
    <div class="hpanel">
        <div class="panel-body">
            <div id="hbreadcrumb" class="pull-right navFloatRight">
                <ol class="hbreadcrumb breadcrumb">
                    <li>CINDATA PLS</li>
                    <li class="active">
                        <span>新增机构</span>
                    </li>
                </ol>
            </div>
            <h2 class="font-light m-b-xs">
                新增机构
            </h2>
        </div>
    </div>
</div>

<g:form action="externalAccountSave">
    <div class="content animate-panel">
        <div class="row">
            <div class="hpanel hblue">
                <div class="panel-heading">
                    机构主体信息
                </div>

                <div class="panel-body form-horizontal">
                    <g:if test="${flash.message}">
                        <div class="message alert alert-info" role="status">${flash.message}</div>
                    </g:if>
                    <g:hasErrors bean="${this.account}">
                        <ul class="errors" role="alert">
                            <g:eachError bean="${this.account}" var="error">
                                <li <g:if test="${error in org.springframework.validation.FieldError}">data-field-id="${error.field}"</g:if>><g:message
                                        error="${error}"/></li>
                            </g:eachError>
                        </ul>
                    </g:hasErrors>
                    <g:hiddenField name="code" value="${params.code}"/>

                    <div class="form-group">
                        <label class="col-md-5 control-label is-required">城市</label>
                        <div class="col-md-3">
                            <g:select class="form-control m-b" name="city" id="city" from="${com.cindata.City.list()}" optionValue="name" optionKey="id" value="${this?.account?.city?.id}" noSelection="${['': '请选择市']}"/>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-md-5 control-label is-required">行政区</label>
                        <div class="col-md-3">
                            <g:select class="form-control m-b" name="district" id="district" from="${com.cindata.District.findAllByParentArea(this?.account?.city)}" optionKey="id" optionValue="name" value="${this?.account?.district?.id}" noSelection="${['': '请选择行政区']}"/>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-md-5 control-label is-required">机构名称</label>
                        <div class="col-md-3">
                            <g:textField class="form-control" type="text" name="name" id="name" value="${this.account?.name}" placeholder="请输入机构名称"/>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-md-5 control-label is-required">机构联系人</label>
                        <div class="col-md-3">
                            <g:textField class="form-control" type="text" name="contact" id="contact" value="${this.account?.contact}" placeholder="请输入机构联系人"/>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-md-5 control-label is-required">机构联系方式</label>
                        <div class="col-md-3">
                            <g:textField class="form-control" type="text" name="phone" id="phone" value="${this.account?.phone}" placeholder="请输入机构联系方式"/>
                        </div>
                    </div>
                    %{--<div class="form-group">--}%
                        %{--<label class="col-md-5 control-label is-required">工作流</label>--}%
                        %{--<div class="col-md-3">--}%
                            %{--<g:select class="form-control m-b" name="workflow" id="workflow" from="${com.cindata.Workflow.findAllByType(com.cindata.dictionary.WorkflowType.findByName('机构'))}" optionValue="name" optionKey="id" value="${this.account?.workflow}" noSelection="${['': '请选择工作流']}"/>--}%
                        %{--</div>--}%
                    %{--</div>--}%
                    <div class="form-group hide">
                        <label class="col-md-5 control-label is-required">启用状态</label>
                        <div class="col-md-3">
                            <g:select class="form-control m-b" name="status" id="status" from="${[[name:'启用',value:1], [name:'禁用',value:0]]}" optionValue="name" optionKey="value" value="0"/>
                        </div>
                    </div>

                    <div class="form-group">
                        <div class="col-md-3 col-md-offset-5">
                            <g:submitButton class="btn btn-info" name="update" value="保存"/>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</g:form>
<g:javascript>
    $("#city").bind("change", function(){
        $("#district option").remove();
        $("#s2id_district span:first").html("请选择行政区");
        var city = $("#city").val()
        $("#district").append("<option value='' >请选择行政区</option>")
        if(city=='-1'){
            return
        }
        $.ajax({
            url: "/district/getDistrictByCityId",
            type: "POST",
            data: {'city': city} ,
            success: function(result){
                console.log(result)
                for(var i=0; i < result.districtList.length; i++){
                    $("#district").append("<option value=" + result.districtList[i].id + ">" + result.districtList[i].name + "</option>")
                }
            }
        });
    });
    $("#city").change();
</g:javascript>
</body>
</html>
